First working version of adaptive