Add stdout flushing where required