moved ai code to lib/ai.py - Not working yet