Worked around segfault. Moved protocol to a class. Improved padding so it supports binary data