added both sides of impurity calc