bug fixed in distinct substrings, todo quicksort change to Max's version