Repaired key list merge function