more refactoring and cleaning up