Refactor test code a bit