First attempt at implementing rmax algorithm.  Does not work.