fix the logic