Improved template selection (now case insensitive).