changed compareTo() to also sort by lexicographical order