nit: return `cookies.get(0)` if the size is exactly 1? That way you save an allocation in the common case.