Clean up cookie checking code