Fixed faulty logic