fix flattenBlocks