added functionality to resort to templates if neccessary.