Fixes to pam script

* Fix #72
* Cleanup code
* Fix occasional segfault due to syslog connection failure