fixing the if logic