Revert "take file flush out of main"

This reverts commit f53ebb921e6e456e13c0cc0cbc0525da48db2fe9.