Update with Sim.R to separate out functions