Handle exit from MPI environment properly