Script inserts missing thead and moves first tr

This script works just the same as before by default but now if there is
no thead element a thead is inserted and the first row is moved into the
thead element. This allows the script to work in  places where a proper
thead may not be generated.