Fix ai.py issues