Fix bug: orphaned units and courses are not handled correctly.