Added defensive code in the database deletion
Pushed the last version of the refactor