Clean up the code to handle Item lists

Reviewing the code while investigating
https://cfengine.com/dev/issues/4812
and looking for potential causes of cycles, I noticed plenty that could be improved.
See individual commit messages for details.