Refactor the rest of the code to match the new model interface
Merge branch 'master' into tests_doc