refactor the code run in a subprocess into a method