Globals removal

Add both -Wmissing-declarations and -Wmissing-variable-declarations.
Fixes all declaration warnings, now there are lots of unused functions.
I didn't want to remove any code in this PR. It's out of my scope to decide if it's just unused by accident. I hope they will be fixed in the next weeks.