More refactoring and testing.

Still can't seem to get the tests to play nicely with reactive ui.