move denominator computation out of main loop