Improved cookie handling