Moved some javascript around so the pages only load what they need