Rewrite document to c

WIP don't merge yet