Prime and squarefree values of polynomials in moderately many variables