random npid generation, and some error handling that i've had to add in for weird reasons