CLEANED UP: extracted message serializing and dezerializing