Some test code cleanup and refactoring.