Fix (3*b)^2=3*b^2 bug
improve code