Refactor teardown method in tests