lots n' lots of refactoring