better control of child processes, refactor