Move common code to new runProgram() method