Well a very good outline for doing enemy AI to avoid bugs is doing a switch statement. So you would have something like:
switch (mode)
{
case 0://Walk to player
{
//walking code
};break;
case 1://Attack player
{
//attacking code
};break;
case 2://Die
{
//dieing code
};break;
}
Then lets say you want the enemy to move to the player after falling off a building or something. All you have to do is this:
You will obviously have to fill in the comments but that gives you a good outline on how all AI should look like. There is of course other alternatives but doing this method avoids a lot of bugs because the object (enemy) can only do one of those case statements at once no matter what.