second version with bdd + cleaning