Added defintion for ai function