finished toArray function