Update weight function and fix 2D.