Added safety checks to avoid duplicate JS