Refactor JS so only the calls that need to happen occur on each page