for some reason e.setPropertyObject recreates the attribute if we have the e.removeAttribute before the if, and it seems it is causing the issue 165.
Note that this pull request have many commits, not only the first ones I created the pull, because I cannot have more than one pull-requests