improved the code about reading cookie