Improve handling of directories