added marshalling across pipe. Moved code into other files