Improved database detection.  Fixed permissions.