Fix setvisibility() function.
Code cleaning.
Minor refactoring and code cleaning.