Mainly refactoring to use MainPipe and ErrPipe
Mainly refactoring to use MainPipe and ErrPipe