Extracted common code from test code