added maximal path code