modified code for getting searchByKeyRange