Fixed handling of directories