Added comments and improved code.