Factoring out a common function for checking arity.