Refactored some code from tester.go into util.go.