Added listening thread function