Updated simulation code