few mods, see comments in script.