refactor test helper code