[WIP] add support for secondary indexes

Could you add a .slice() here to make sure that we don't modify the original index structure with the pushes further down?