Fix handling of missing key fields and add test.