Fixing a bug in the template selection