refactor model builder codes, and init freemarker