Refactor b64 encoder and sockets.
Merge Julian's socket code with Tim's manager outline.