updating for keypayload null check.

adding NULL check to make it fail safe.
Not sure about the return value.
Please review and merge if required.