Fix problems with util.py and add tests.