more comments and refactoring.