instead of doing a sum each iteration - maybe keep the sum pre-computed ?