refactoring and more comments