Refactor with namedtuple