Handled shuting down threads in a better way.