eliminate global variable and fix indentation