Refactoring and cleaning up test code (a bit)