refactor quit mechanism