refactor, better way to obtain stdout from Popen