Added selected element null check