Move monkey-patching into util.py