You can reduce lines 677 through 679 to just:
if(exact){
   return exactlyName;
}