Added logic to remove unecessary HTML elements when there is no content.