Move all locals to top to avoid global vars going into functions.