Remove SEARCH option and simply check for ${2}. If set, use ${2} as REGEX for which to search the keyfile.
Fix list of vars in the unset calls.