fixing bad toArray() method