fix bug with hanging on exit