Added some extra safeguards against problems when running a headless linux app.