refactored checking of function arity