Nested elements are not being removed

Fix for #26 but I only unit tested this singular function. I am not sure how it will play with rest of code.