Fix async execution
Clean lua state and threads on flush
Add terminator task to finish workers