Further modifications to new code to better handle corrupt databases.