Fix error on cookies and write tests for it