add sorting functionality to the index method