fix exit handling