Added indexing, fixed sort