Fix header parsing and cookie saving