Fixed some undefined checks that ought to have been null checks