added formatToDocument
cleanup