Update formatting

Moved nested function declarations to top of their scopes