Added stdout flush statements at strategic points