implemented simulation code