refactoring and then some more refactoring