Changes to pickling (inspired by blueeyes)