Cleaned up AI code