added check for headless environment