add handling for tuples; refactor