Wrap code in document.ready and add js to create table headers