corrected logic