fixed destroy function to reset the idcounter