more cleanup and refactoring.