Generalized the script in preparation of the firefox add-on