fixed wrong filename in popen, added some error fallbacks