Secondary indexing & general spring cleaning

This PR combines Hardik's secondary index work with some clean-ups from my end.

Also see https://github.com/gwicke/restbase/tree/index_cleanup for the matching RESTBase change for the index structure.

@seanpringle: If you'd like to review this before we merge with master, then please go ahead!