Logic for generating the tuples