move handle sub process into separate function