updated error handling and tcp socket work