Move all the code for 'model' into the model module

Remove $.extend hackery.