Working reduction algorithm, without ordering or path removal.