Rewrite flatten array