Quote the String used in the fuzzy match. (@zendeavor)
Use ${path##*/} instead of basename. (@zendeavor)
Use ${path%/*} instead of dirname. (@zendeavor)