set global variable and cleanup code