Add test for previous id removal and fix bugs
Some refactoring and cleaning
Add missing test assertion