working to calculate D2 in bins