Moving keyset to inner loop to ensure that new keys get considered in next iteration