Split listener and sender functions. Simplify data flow