cleaning up exits to avoid bad writes