Fix edge cases w.r.t. empty and one-element key/value lists.