pull out compute_nonlocal routine