fix faulty logic