Fixed bug where waitpid could be interrupted (thanks Russ)
Revamped input and output gathering