backporting #423 into 0.9.12

pickle fix needed the import sys from later version of util.py