fix up and refactor custom template loading