added more flexible toggle handling