Move geometry parsing into function
Move variable declarations to top

C99 is much more flexible with where declarations can occur, but let's
stick with with the traditional constraint of putting them at the top of
a function for better compatibility.