Rearranged a lot of the default javascript so that it is down to two page loads