modification in toggle function