Just a small thing. I think you should make a function called init(), this would make it more clear, that you are initializing and not  "re setting" the variables from start. I did undetstand it, but not at first.