Check for undefined keys before merging values