fix flatten method to accept flattening of arrays