refactoring and adding documentation comments