Refactoring and template clean up. Simplify tpl package.