fix deadlock when sending exit status and some clean up