Working AI code