Additional cleanup and refactoring