Comments, cleanup, fixed logic in simulation algorithm