refactor tuple factory to simplify logic, also add index discovery on tuple