Add toArray method, remove old code