optimize minor logic, but still failed in extreme case