Use a refcounter for the thread. Fixes #4.

This seems to allow multiple pages to work now, and cleanup when closed.
Firefox appears to stop receiving events once one tab has been closed
however, but I will open a new bug for that.