fix a bug where missing key can cause 'nil' in output