Split some functionality to controls module, resolve scoped varaible issues