Added rmax with shaping function