fixing extending flattening to work with non-trivial indexing