Added isDefined checks for elements that needed it