Rewrite toggleVisibility function
Rename functions and add comment to make things clearer