refactor test code a bit