Reestructure some code in cookie handling.