Shouldn't flush() be in finally section? I think this would be better read if it was multi-line...