Script local variables and functions and a couple of bug fixes.