Fixed some file flushing bugs
added TODO