Correct prefix search logic

Selecting the smallest prefix iteration using `prefix.length > name.length ? name.length : prefix.length` was incorrect as a smaller name (zero length) would not be iterated and it'd return the old prefix.