added a stdout flush after print statements.