Improve documentation and arrangement of model code