Improved handleing of directories