021: moved class toggle logic to a function