Updated to take more chances with templates.