added simulation code