Move the cookie serialization code into cookie