Refactor, fix templates