refactored hide/show logic