fixed divide by zero check