Updated sim.R with comments and test. Committing before refactor / writeup.