Fixed thread issue
Fixed memory leak