refactor
add thread
fixed bugs
wip