Remove global variables, add global scope and cloning.