corrected logic error