Move these two lines outside the for loops to compute them only once.