changed D_max to pair D that specifies the range