fixed incorrectly outputting to stdout and stderr causing incorrect output when redirecting into a file