Fixed cookie handling.

I don't understand what this code was trying to do. So perhaps there is something I don't understand.  But this patch fixes my problem.