fix mutex unlocking in wrong order