refactored code to minimize repeating test code