Lots o' refactoring