Now your solution seems to be OK. I wish you full marks for this assignment, but I think that it would be really good if you learn how to check this by yourself using debugger.

Regards,
Hob