fixing the logic