Fix some bugs: threshold problem, Zero division