Check the sum[0] before division to prevent the division by 0 error