Index cleanup

This PR combines Hardik's secondary index work with some clean-up from my end.