Fix check for pwd which won't throw KeyError.