cleanup and refactoring