lots and lots and lots of refactoring