Added toArray method and test