refactoring, added comments