Adding toggling in a function