Moving some JS

Moving the JS to the bottom to prevent interruption and blocking when
loading the page.