Added lexicographical sorting.