Some refactoriings to avoid problems with reuse

Bug fixed. thanks to @jairobjunior