Add judge_doc tests. Refactor some things.
Minor coding fixes.