updated toArray() method