added server thread function