fix the bug in weight functions due to divide by zero