Add test; fix null pointers exposed by test