Refactor iterKey & iterValue

This commit lifts the common code from iterKey and iterValue.