Refactored tearDown code