Refactor template url resolving