Improved logic behind cookie handling introduced 401 forbiden access error, fixed some bugs for whose fault server didnt work