added missing libraries and refactoring on tag escaping