more cleanup and refactoring