add threading
some adjustment
add unittest
some adjustment