Improved client error handling. Implemented #4