2 implied globals put in scope

Lines 1143-4 start and end vars are not defined.

Move the variable declarations to the beginning of the function to stop them from becoming globals.  

No compiled js because of anticipated conflicts with other Pull requests.