Continue refactoring code by splitting the msg processing from the sendrecv code