Upgrade to lock functions. Only enabled in debug