implements toggle code