refractored and cleaned up toggling code