added tally function