for visual studio move var declear to head of function