fix popen invocation parameters and some cleanups

this will also close #36