minor cleanup and refactoring