clean exit from userscript. Fixes #475