Making sure elements exist and are not `null` before accessing properties