added sorting algirthm that sorts by common substring