some formatting & remove repeated code for child processes