implementing the thread