updated simulation code