Debugged adaptive version.