Add some null checks to the namespace check and autorefill.

Fixes #147.