Refactoring out global variables from main controlscript