Refactored but in broken state.
Refactored and working correctly. Committing prior to additional work based on ideas from http://schemecookbook.org/Cookbook/StringRecipeDecodingBinaryMessages.
A more functional implementation.