modified code to make sender a bit more efficient