Optimizing dir()