toggle function improvements