Make sure we don't crash on invalid HTML.
Fix potential NPE.