general refactoring and comments