refactoring and adding comments
refactor