Move var definitions to top of each function