Do not rely on outdated _index

Instead, calculate the index with indexOf - should be no problem since we
only do this once.

Also made some cleanups to remove side effects and reduce array lookups.
merge with ahocevar/largegeom