Make a couple of variables not so global.
Don't process the document node itself when walking up the DOM.
Testing, testing, 1 2 3.