Enable calculating on multi thread.
Fix Thread bugs.