small speed improvement, move assignment outside loop