Pickling

Merge of #638 to master.