added adaptive algorithm