WIP - fix flattenBlocks