Added defensive guards.

To protect against cases of invocation with null arguments.