Fixed bugs in simulation.