Separating variable declaration from first assignment, which should fix some ksh problems.
Use "typeset" instead of "local" for portability