refined code related to thread