Attempt to fix NRE reported by pantheis  & toadicus

And add some comments