cleanup for async thread code; introduced lock

https://trello.com/c/oIMe4i0q/341-threading-issues-with-async-calculations