Lots of refactors to make this all clean and get us good code coverage.