Check key exists before looping