Re-organize code as Threading