More work on template system
Added main function
Started replacement code for model template