Fixed some bugs.

Flush will only return when all workers have flushed.