fix typos in code; add first draft to tex; add python code to doc