First commit of the autoretreat code