move variable definitions to top of function because of hoisting