19863 fix wedge

The NullPointerExceptions caused by attempting to send messages during disconnect can leave scalang in a state where it is always trying to monitor non-live process (having failed to send a MonitorExitMessage).

The main fix here is the last commit which ensures we don't throw a NullPointerException in write(). The other commits tidy the code for clarity for the most part.

BugzID: 19863