Full code review

Full code review
The global variables used in estimating model parameters. Gamma has been now moved to a per-document variable.