fix exit condition