more robust cleaning of database