Some code cleanup in the model. Should made it easier to write new models.
Some more refactoring
Deleted some unused functions
Merge branch 'model_refactory'