Added common function to compute avg and handle div by 0