fix potential divide by zero errors