refactored roundtrip code