reorganize code to save some fp multiplications using iterate(), name index 'n' consistently