added fflush() to suitable places
Merge branch 'hotfix/flush_log'