utils.py: fix a bug with lists of things, add test coverage