added sorting to index_by_id