memory leaks fix, flush_results bug fix