added adaptive retmax