replace global variables with local