tidied up util.py; fixes #151