fixed bug when using rex as a library and using sudo - #414