Guard against empty lists.

Also use clearer naming of departments.
Move document type out into metadata line