Refactor deactivation handler