fixed nested loops order and score summation