Additional fixes when IO is redirected

Credit goes to Keith Kitka for finding the bug and fix