Added comments, and refactoring.