fixed possible division by zero