Fixed bugs in exit handling