Improved comments and i/o handling in sim.py; untested.