redone without using global variable