Added globals.h and reorganised usage of it.