Improved client error handling and logging.
Implement close state.