Refactor some I/O things
Remove unnecessary fflush call