Loop averages and partition functions in U(N) gauge theory on two-dimensional manifolds