Code cleanup of the simulator. Inline documentation added.