Generate hash with table header and optimize