Modify toggle function to use internal functions for easier overriding