Improve name recognition

Entire algorithm is in the comments on the header of the function, also making name matching case insensitive.