refactored code into firefox plugin