localized sort, fixes #177