Lots of refactorings