fixed issues with output when redirecting stdout