Modified version of the communication code using mediator thread and looper