Made threads ctrl-c safe