Added toArray() function