refactor into a `while`
add test case exercising checking that element !== document prior to matching
Merge pull request #3 from treygriffith/master

refactor into a `while`