Fix typo, introduce heuristics to speed up directory detection