fixed the logic