working version of sending and receiving msg