cleanup: put cpid stuff into own method with try catch