fixed resize code for headless running