Added mutex_lock/unlock in functions;