refactored
toggle functionality