Redmine/6553: Fix implicit looping over multiple lists

Pull request for initial review of the changes to the code. Planning to add more test coverage to the acceptance test before merging.
s/is null or/is empty or/.
Granted, an empty list is represented by a NULL pointer, but the relevant property of it is that it has no entries; i.e. it's *empty*.