improved cookie handling