Working simulation, with code comments