Refactored send() function