fixed clean termination at the end of the simulation
added shmem cleanup at the end