Wrote basic, but proper, simulation code