Refactored code for tuples