simulation code