Fix undeclared "tmp" variable
Refactor: move RegExp trick into getParentDir()