fix the logic bug