further cleanup and refactoring