more cleaning up and refactoring