Fixed mutex locking bug