Add some error handling for sockets