fix error in simulation code