cleanup and refactoring improvements