Improved envelope serialization