Mostly formatting

Also reduce the scope of some variables