add in some more debugging
update code to move variables to top of functions as hoisting would