improved spawn and submit script