fix popen invocation parameters and some cleanups