Added conditional logic to the javascript to test for elements existence.