Refactored quitting method