Fixed some race conditions.
Merge branch 'dev'