Code cleanup

Improved code by adding timeout to the transmit and