Refactored code so that both perf test and regular test would share common code.