Slightly refactor to fix a warning in headless mode.