Refactor for cleaner test setup and teardown.