Added rmax with shaping.  Fixed vi in rmax.