Fixed index/rindex and added test.