Fix simulation loop