some more refactoring and cleaning up