Lots of nice refactoring