Added comments. Improved code quality.