Refactoring to StdIO

Refactoring to support moving from TCP link to std in / out