Fixed TX, bug fixing and more refactoring

Signed-off-by: Carlo Caione <carlo@caione.org>