added round-trip test
some refactoring