More work on AI, added state conditional changes.