Globals removal

Add both -Wmissing-declarations and -Wmissing-variable-declarations.
Fixes all declaration warnings, now there are lots of unused functions.