split recieving processing and sending part into functions