Fix lock when stopping under certain stop conditions
Merge branch 'master' into staging