Improving code shouldSetUndefinedKeys