fix a bug causes infinite loop in find_head()