Simplify the calc_D() function and make it  work better with the function sep_orders()