Added logging for database errors