Added a guard to prevent possible division by zero errors.