Minor refactoring of get_template