fix bug 1044068 - Prevent 'Cannot call execute of null' errors

This is a working PR and should be treated as such.  Likely lots of conversation below.

Still to complete:

- [x] - A test to confirm my PR prevents the issue.
looks like this `key` assignment is over-written on the next line?