Fix potential divide by zero errors