Added additional check when running headless.