Some fixes making pam detection more resilient.