attach/detach thread.
refactoring & performance tuning