Cleaned up the code I added in the previous commit for pickling/unpickling.