simplify flatten and concat, fix a test, remove unnecessary usage of flipIndices