Changed to subprocess instead of popen, seems more stable