Bug fix and better cookie handling