add fixes courtesy of Élie Roux to the database code