Merged algorithm of edit_tuples() into edit_state()