got rid of globals in for loop