fixed toggle function