fixed problem in thread-closing