fix key exists vs null check critical for expand queries