Cherry pick from 69dbbbec4b: Moving globals into a struct (currently also global :) )