Fixed some NPE's when running headless