Properly clean up and restore class state after deregistering the last hook.