Fixing a NPE for cookies and cleaning up code.