move the contribution calculation outside of the loop