Added docstring and cleaner subprocess management