fix possible race condition when checking if pin exists