improved function to read cookies from file