Fixes bug with duplicated nested elements

We need to first select the elements, filter the 
not wanted ones from the elements and their child
elements recursively.

Thanks @Cartroo for help with the fix.