Added some useful comments on my code. Enjoy :)