added thread function to server