Better error handling and fixed cookie handling

The cookies implementation was a stub that wouldn't work correctly.
That has been fixed.  In addition, the program exits for certain
failures now.