Fix bug: exit gracefully