Handle empty directories in a better way