Updated js to wait for elements to exist