Made the checks and process for sending / receiving into a function to clean up code