fix some error in simulation code