moving send code inside each function