avoid the extern keyword in .cpp files
remove unused globals

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