implemented encoding and sending