Convert over to subprocess from popen. I'm sure there are bugs here