fix a potential bug, which might lead to large complexity