Could you comment the code to be more clear about what does what? I'm having trouble modifying it and using it for my own needs.