Fix thread problem. Improve stability. Add comment.