Merged in NPC controller code.