workable for both sending and receiving
refactor