add helper funcs & fixing transmit thread

* added more helper functions to simplify the transmit thread logic
* fixed transmit thread more....it still needs more work doee

TODO: continue fixing the transmit thread