fixed bug with ending of simulation