code review: declare variables outside loop