fix toggle switch close behavior; add extra sanity checks; remove whitespace