refactored more code in testing.