remove unused globals

Also change globals into statics which are only used in one file