Possible (arguably safer) alternative to pickle for cookie serialisation

Addresses issue #447.