improved file buffering via addition of stdout flush statements.