refactors togglePin action