modified tally function