merged kisskys/master_flush_optimization_and_bug_fix to master