Remove trailing spaces (most of them anyways). Add some logging to the example. Add encoding option for incoming data.