properly handle divide by zero errors