Added NPC conditional handling and moved state handling around.