Fixed a bug with PDO exception handling (plus some cleanups)

Fixed a bug with PDO exception handling
Fixed a few minor issues
Some cleanup of trailing spaces (automatic from IDE)