Improved message writing functions and tests, fixed bug in parsing format option
Fixed writing single-part messages