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.
If state is not a cf_null, the code used to unconditionally advance it by one; now you don't.
Is this because you're taking the first entry in the list, which used to be a spurious cf_null that you no longer waste time prepending in the first place, so no longer need to step over here ?