implemented sorting on index