small cleanups

A bunch of small pedantic cleanups.
It start to get half interesting in the last commits when I get rid of some globals.