fixed termination condition in simulation