Updated 2-cookie solution, now works as expected.