Fixed packet tx from tcp rx, refactored some code