Refactored some test code