also optomizing the npc code for better performance