Add guard against Element not being defined