add some more elaborate nil check