Secondary indexes, major refactoring & cleanup