Uncomment takeWhile and remove unused code in AI