Fixed infinite loop when quitting (sometimes)