The namedtuple should be defined outside the function.