Fix build on windows with Visual Studio

Move declarations to top of the function.