Avoid all uses of globals.
Fix bugs with docs (some parts of last commit was bugged)