It's good to hear that you have managed to solve the problem; it would have been impossible for me to catch that bug. The good news is that now you've learned how the code works, so you'll be able to tweak it according to your needs.