Fixed toArray method