Change toArray implementation