fixed bad exception and socket.write calls