Update according to @deguio suggestion. Also protect against null
pointer.