AD improved (-> function def shifted to Main)