My own try of adaptive code