Refactor, using namedtuples, other logic changes