for loop needs fixing