Added nullPtr check