check if is defined before accessing property