Corrected logic in simulation