WIP: Ws client code

For future, tell yourself that when you have to use this many `return` statements, you should actually be breaking things up into separate functions.  This is a sign that you've got too many paths joined into a single function.  In reality, each of your `return` statements marks the boundary of a sub-process, which should be placed into a separate function.