rearranged so plotting happens completely after calculations for D2