added toArray function