changed max dist to the longest string