Code refactoring and changing

Refactoring code and changing use of REGEX to use of DOMDocument