fixed error in toArray()