Initial refactoring and validation of stdout and stderr.