Further work on refactoring so tests will actually work at some point