Refactored send and receive functions.