Fixing the AI  bug and making things a bit DRYer