some comments and refactoring