Refactor some tests and helper methods