declare index as local var
Merge pull request #117 from baranga/fixGlobalIndexVar

declare index as local var