more robust arity computation, leak fix