fix memory leak/erros in run_system