wrote code for runSimulation()