now uses flush() to improve thruput