handle errors in executables and closing connections