Better subroutine extraction

A bit slow, but it looks for the best shrink
at each step. Not guaranteed to be optimal
(greedy algo, might get stuck on local maximum)