fix exit bug (this might be behind mac crashes?)