large Cleanup :)

please review carefully, I've removed a vast amount of globals and two unused functions.. AFAICS my local repo still works without errors :)