Pull index out into it's own object
Add Index tests and fix subtle bug