Cleaned up array duplication and html function

Made the insert html function more robust to handle inserting html
variable better and smarter.