Stupid logic error