minor mods to make script more general