Some more tidying.

Fix a bug in the previous tidying.
Fix at least one potential NPE.