fixed issues with program shutdown when typing 'q' two times would crash the program. also serious fixes to the exit routine