added sorted index function (whoops)