more comments and refactoring