rewrite cookies managment, don't use a temporary array