Added ability to periodically flush buffer