fixed "preLen" function to handle lengths smaller than 10