VID-1582 Move variable declaration closer to where it is used