closing threads in a nicer way