lots of nice refactoring