refactoring to make nonstdio more readable