Flush stdout after writing to stdout
Small refactoring