refactor code by replacing iterations where we remove invalid htmlElement by the java 8 replaceIf fuction