Refacterd mutex_lock