Added some extra marshalling/unmarshalling logic.