Added an extra nullreference check