Adjusted the document toArray method.