adding comments and refactoring methods