refactoring and adding methods and comments