Refactored the way to switch stdio