added empty directory handling