Code cleanup and bugfixes

Signed-off-by: zubietaroberto <zubieta.roberto.e@gmail.com>