Fixed toArray helper