Added comments. Improved code.