Fix some N+1 problems.