Moves HTML generation to input phase.
Added full document parsing.
Cleanup and bug fixes (off by 1).