Added q as exit option, added extra error check to clean up, fixed bug causin terminals to break if program exited unexpectdly