Bug fixes to make the toggle switch work