refactored AI into its own class

also tried working around the empty widget/stack crash that's been
popping up for some reason.