Finished test refactoring. Not yet debugged.
Intermediate bugfixing commit. Not all tests pass yet!!