Added html replacement logic and refactored.