readmsg and sendmsg made into fucntion