refactoring npc code