Added reset, more debugging, socket error handling