check for total == 0 to avoid division by zero