flatten to 2d (another version)