Simulation now terminates properly, added comments