fixed add_subcosts inner-function position