Fixed issue with javascript running only on page reload