small refactoring and adding comments