Added better pid checking